Modification start date
[BattleCats.git] / Assets / Scripts / Depreceated Scripts / YarnMovement.cs
blobc34880622157d011422907a96311399e6199570d
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
5 public class YarnMovement : MonoBehaviour {
7 [SerializeField]
8 float moveSpeed;
9 [SerializeField]
10 LayerMask whatIsGround;
13 private Animator anim;
14 private Rigidbody2D rb;
15 private Vector2 facingDirection;
16 private float groundCheckRadius = 0.1f;
17 private Transform groundCheck;
18 private Transform spriteChild;
20 private bool isRolling;
21 private bool grounded;
23 void Start () {
24 anim = GetComponent<Animator> ();
25 rb = GetComponent<Rigidbody2D> ();
26 groundCheck = transform.Find ("GroundCheck");
27 spriteChild = transform.Find ("OutsideSprite");
28 facingDirection = Vector2.right;
31 void Update()
33 CheckGround ();
34 MoveYarn ();
35 updateAnimation ();
39 void CheckGround()
41 Collider2D[] colliders = Physics2D.OverlapCircleAll (groundCheck.position, groundCheckRadius, whatIsGround);
42 foreach (Collider2D col in colliders) {
43 if (col.gameObject != gameObject) {
44 grounded = true;
45 return;
48 grounded = false;
51 void MoveYarn()
53 isRolling = false;
54 if (Input.GetButton ("Left")) {
55 transform.Translate (-Vector2.right * moveSpeed * Time.deltaTime);
56 FaceDirection (-Vector2.right);
57 isRolling = true;
59 if (Input.GetButton ("Right")) {
60 transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);
61 FaceDirection (Vector2.right);
62 isRolling= true;
66 void FaceDirection(Vector2 direction)
68 Quaternion rotation3D = direction == Vector2.right ? Quaternion.LookRotation (Vector3.forward) : Quaternion.LookRotation (Vector3.back);
69 spriteChild.rotation = rotation3D;
72 void updateAnimation()
74 anim.SetBool ("isRolling", isRolling);